<?php
require 'db.php';
$sqlstr="select * from shopping";

$result=mysqli_query($link, $sqlstr);
$data=mysqli_fetch_all($result);

header("Content-type:application/vnd.ms-excel;charset=UTF-8");
header("Content-Disposition:filename=data.xls");

mysqli_free_result($result);
mysqli_close($link);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文件下载</title>
</head>
<body>
<table width="1000" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="gainsboro" bgcolor="#d3d3d3">
  <tr>
    <td><div align="center">ProductName</div></td>
    <td><div align="center">Model</div></td>
    <td><div align="center">Price</div></td>
    <td><div align="center">Quantity</div></td>
     <td><div align="center">Status</div></td>
  </tr>
  
		<?php 
		for($i=0;$i<=count($data);$i++){
		?>
		<tr>
			<td><?=$data[$i][0]?></td>
    		<td><?=$data[$i][1]?></td>
    		<td><?=$data[$i][2]?></td>
    		<td><?=$data[$i][3]?></td>
    		<td ><?=$data[$i][4]?></td>
		</tr>
		<?php 
		}
		?>
</table>
</body>
</html>